<template>
    <div class="cartcontrol">
      <transition name="move">
        <div class="cart-decreas" v-show="food.count>0" @click.stop.prevent="decCart">
          <i class="iconfont decreas">&#xe64c;</i>
        </div>
      </transition>
      <div class="cart-count" v-show="food.count>0">{{food.count}}</div>
      <div class="cart-add" @click.stop.prevent="addCart">
        <i class="iconfont add">&#xe675;</i>
      </div>
    </div>
</template>

<script>
import Vue from 'vue'
export default {
  name: 'CartControl',
  props: {
    food: Object
  },
  methods: {
    addCart () {
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1)
        // this.food.count = 1
      } else {
        this.food.count ++
      }
    },
    decCart () {
      if (this.food.count) {
        this.food.count --
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  .cartcontrol
    font-size 0
    .cart-decreas
      display inline-block
      padding 6px
      transition: all 0.3s linear
      &.move-enter-active,&.move-leave-active
        opacity 1
        transform translate3d(0px,0,0)
        .decreas
          display inline-block
          font-size 24px
          color rgb(0,160,220)
          line-height 24px
          transition: all 0.3s linear
          transform rotate(0)
      &.move-enter,&.move-leave-to
        opacity 0
        transform translate3d(24px,0,0)
        .decreas
          transform rotate(180deg)
    .cart-count
      display inline-block
      width 12px
      font-size 10px
      color rgb(147,153,159)
      text-align center
      vertical-align top
      line-height 24px
      padding-top 8px
    .cart-add
      display inline-block
      font-size 24px
      color rgb(0,160,220)
      padding 6px
      line-height 24px
</style>
